package com.huaxinkaiye.adapter;

import java.util.ArrayList;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONArray;

import com.android.volley.toolbox.NetworkImageView;
import com.google.gson.Gson;
import com.huaxinkaiye.R;
import com.huaxinkaiye.application.HuaXinApplication;
import com.huaxinkaiye.bean.PictureRows;
import com.huaxinkaiye.bean.RowsBean;
import com.huaxinkaiye.utils.SimpleClient;
import com.huaxinkaiye.utils.UrlUtils;

import android.content.Context;
import android.os.Message;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class NewSQListAdapter extends BaseAdapter {
	private Context context;
	public ArrayList<RowsBean> rows = new ArrayList<RowsBean>();
	public String url ;
	public NewSQListAdapter(Context context) {
		// TODO Auto-generated constructor stub
		this.context = context;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return rows.size();
	}

	public void add(ArrayList<RowsBean> rows) {
		this.rows.addAll(rows);
	}

	public void clear() {
		this.rows.clear();
	}

	@Override
	public Object getItem(int arg0) {
		// TODO Auto-generated method stub
		return this.rows.get(arg0);
	}

	@Override
	public long getItemId(int arg0) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public View getView(int arg0, View convertView, ViewGroup arg2) {
		// TODO Auto-generated method stub
		ViewHolder holder;
		if (convertView == null) {
			convertView = LayoutInflater.from(context).inflate(
					R.layout.chujian_item, null);
			holder = new ViewHolder();
			convertView.setTag(holder);
			holder.im_che = (NetworkImageView) convertView.findViewById(R.id.im_che);
			holder.te_chepaihao = (TextView) convertView
					.findViewById(R.id.te_chepaihao);
			holder.te_kuwei=(TextView)convertView
					.findViewById(R.id.te_kuwei);
			holder.te_chuangjiantime = (TextView) convertView
					.findViewById(R.id.te_chuangjiantime);
			holder.te_danganbianhao = (TextView) convertView
					.findViewById(R.id.te_danganbianhao);
			holder.te_yanshe_weizhi=(TextView)convertView.findViewById(R.id.te_yanshe_weizhi);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		  
	    //Log.e("--ppp--",getPictureUrl(rows.get(arg0).getId()));
		for(int i=0;i<rows.get(arg0).getPictures().size();i++){
			if(rows.get(arg0).getPictures().get(i).getFileType()==1){
				holder.im_che.setImageUrl(UrlUtils.host+rows.get(arg0).getPictures().get(i).getFilepath(),
						HuaXinApplication.mImageLoader);	
			}
		}
		holder.te_yanshe_weizhi.setText("车身颜色："+rows.get(arg0).getCarBodyColor().getMean());
		holder.te_chepaihao.setText("车牌号： "+rows.get(arg0).getPlateNumber());
		holder.te_chuangjiantime.setText("申请时间： "+rows.get(arg0).getBarginRequestTime());
		//Log.e("rows.get(arg0).getStoreCode()",rows.get(arg0).getStoreCode());
		if(rows.get(arg0).getStoreCode()!=null){
			holder.te_danganbianhao.setText(rows.get(arg0).getStoreCode()+"");
			holder.te_danganbianhao.setTextColor(context.getResources().getColor(R.color.red));
			holder.te_kuwei.setTextColor(context.getResources().getColor(R.color.red));
		}else{
			holder.te_danganbianhao.setText("无");
			holder.te_danganbianhao.setTextColor(context.getResources().getColor(R.color.gray_normal));
			holder.te_kuwei.setTextColor(context.getResources().getColor(R.color.gray_normal));
		}
		
		return convertView;
	}

	public class ViewHolder {
		NetworkImageView im_che;
		TextView te_chepaihao, te_chuangjiantime, te_danganbianhao,te_yanshe_weizhi,te_kuwei;
	}
//	private String getPictureUrl(int carid) {
//		// TODO Auto-generated method stub	
//		final List<NameValuePair>	params = new ArrayList<NameValuePair>();
//		params.add(new BasicNameValuePair("cid", carid+""));
//		new Thread(){
//
//			@Override
//			public void run() {
//				// TODO Auto-generated method stub
//				super.run();
//				try {
//					String data = SimpleClient.doPost(
//							UrlUtils.picturelist_url, params);
//					Gson gson=new Gson();
//					PictureRows pr=gson.fromJson(data, PictureRows.class);
//					url=UrlUtils.host+pr.getRows().get(0).getFilepath();
//				} catch (Exception e) {
//					// TODO Auto-generated catch block
//					e.printStackTrace();
//				}
//			}		
//		}.start();	
//		return url;
//	}
}
